package com.nowcoder.community.service;

import com.nowcoder.community.dao.AlphaDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Service
//@Scope("prototype")    //作用范围,prototype每次访问bean创建新的实例，正常都是单例
public class AlphaService {

    @Autowired      //注入
    private AlphaDao alphaDao;

    public AlphaService(){
        System.out.println("实例化AlphaService");
    }

    @PostConstruct  //这个方法在构造器之后调用
    public void init(){
        System.out.println("初始化AlphaSerivce");
    }

    @PreDestroy     //销毁对象之前调用
    public void destroy(){
        System.out.println("销毁AlphaService");
    }

    //模拟查询业务,service依赖dao
    public String find(){
        return alphaDao.select();
    }

}
